/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package aso.upna.cancion;

import entagged.audioformats.AudioFile;
import entagged.audioformats.AudioFileIO;
import entagged.audioformats.exceptions.CannotReadException;
import java.io.File;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author javier
 */

public class CancionLocal extends AbstractCancion{

    private String path;

    public CancionLocal(String filename,String path)
    {
        super(filename);
        this.path = new String(path);
        calcular_duracion();
        metadatos = new Metadata(getRealPath());
        super.filesize = new File(path+filename).length();
    }

    @Override
    public boolean is_local() {
        return true;
    }

    @Override
    public String getPath() {

        return path;
    }

    @Override
    public String getRealPath()
    {
        return path+super.filename;
    }

    @Override
    public void calcular_duracion()
    {
        try
        {
            File curr_file = new File(getRealPath());
            AudioFile audioFile = AudioFileIO.read(curr_file);

            if(audioFile == null)
                return;

            super.duracion_int = audioFile.getLength();
            super.duracion = convertDuration(audioFile.getLength());
            
        } catch (CannotReadException ex) {
            Logger.getLogger(CancionLocal.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public CancionRemota getCancionRemota(String user_id)
    {
        CancionRemota can = new CancionRemota(super.filename,user_id);
        can.duracion = new String(this.duracion);
        can.filesize = super.filesize;
        can.setMetadatos(metadatos);

        return can;
    }
}
